﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using nGSO.Config;
using nGSO.Model;

namespace nGSO.UI
{
    public partial class SelectFitnessFunction : Form
    {
        private GsoConfig _config = null;

        public AgentFitnessFunEntry SelectedAgentFitnessFun
        {
            get
            {
                return cbxAgentFuntions.SelectedItem as AgentFitnessFunEntry;
            }
        }

        public SelectFitnessFunction()
        {
            InitializeComponent();   
        }

        internal void SetAgentFunctions(GsoConfig config)
        {
            cbxAgentFuntions.DataSource = OptimizationTaskConfig.Tasks.Select(s=>s.Value).ToList();
            cbxAgentFuntions.DisplayMember = "Name";
            cbxAgentFuntions.ValueMember = "FunctionBody";
            _config = config;
        }

        private void cbxAgentFuntions_SelectedIndexChanged(object sender, EventArgs e)
        {
            OptimizationTaskElement selectedFitnessFun = (OptimizationTaskElement)cbxAgentFuntions.SelectedItem;
            tbxFunction.Text = selectedFitnessFun.FunctionBody;
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            _config.SelectedOptimizationTask = (OptimizationTaskElement)cbxAgentFuntions.SelectedItem;
            _config.SetOptimizationTaskParameters();
            
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
